/*    */ package com.iris.egrant.utils;
/*    */ 
/*    */ import java.util.Map;
/*    */ import org.springframework.context.ApplicationContext;
/*    */ import org.springframework.context.ApplicationContextAware;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class SpringContextHolder
/*    */   implements ApplicationContextAware
/*    */ {
/*    */   private static ApplicationContext applicationContext;
/*    */   
/*    */   public void setApplicationContext(ApplicationContext applicationContext) {
/* 21 */     SpringContextHolder.applicationContext = applicationContext;
/*    */   }
/*    */ 
/*    */ 
/*    */ 
/*    */   
/*    */   public static ApplicationContext getApplicationContext() {
/* 28 */     checkApplicationContext();
/* 29 */     return applicationContext;
/*    */   }
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */   
/*    */   public static <T> T getBean(String name) {
/* 37 */     checkApplicationContext();
/* 38 */     return (T)applicationContext.getBean(name);
/*    */   }
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */   
/*    */   public static <T> T getBean(Class<T> clazz) {
/* 46 */     checkApplicationContext();
/* 47 */     Map beanMaps = applicationContext.getBeansOfType(clazz);
/* 48 */     if (beanMaps != null && !beanMaps.isEmpty()) {
/* 49 */       return (T) beanMaps.values().iterator().next();
/*    */     }
/* 51 */     return null;
/*    */   }
/*    */   
/*    */   private static void checkApplicationContext() {
/* 55 */     if (applicationContext == null)
/* 56 */       throw new IllegalStateException("applicaitonContext未注入,请在applicationContext.xml中定义SpringContextHolder"); 
/*    */   }
/*    */ }


/* Location:              D:\文件kjt\WEB-INF\lib\egrant-core-2.2.20240205.1659.jar!\com\iris\egran\\utils\SpringContextHolder.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       1.1.3
 */